<#import "/manage/tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="商品管理">
<form id="searchForm" class="form-panel">
    <ul class="panel-content row">
        <li>
            <div class="control-group span8">
                <label class="control-label">商品编号:</label>

                <div class="controls">
                    <input type="text" class="input-normal" id="id" name="id"/>
                </div>
            </div>
            <div class="control-group span8">
                <label class="control-label">状态:</label>

                <div class="controls">
                    <select name="status" id="status" class="input-normal">
                        <option value="0">全部</option>
                        <option value="1">新增</option>
                        <option value="2">已上架</option>
                        <option value="3">已下架</option>
                    </select>
                </div>
            </div>
            <div class="control-group span8">
                <label class="control-label">商品分类:</label>

                <div class="controls">
                    <select name="catalogSelect" id="catalogSelect" class="input-normal">
                        <#list catalogs as item>-->
                            <option pid="0" value="${item.id!""}"><font color='red'>${item.name!""}</font></option>
                            <#if item.children??>
                                <#list item.children as item>
                                    <option value="${item.id!""}">&nbsp;&nbsp;&nbsp;&nbsp;${item.name!""}</option>
                                </#list>
                            </#if>
                        </#list>
                    </select>
                </div>
            </div>
        </li>
        <li>
            <div class="control-group span8">
                <label class="control-label">新品:</label>

                <div class="controls">
                    <select name="isnew" id="isnew" class="input-normal">
                        <option value="">全部</option>
                        <option value="y">是</option>
                        <option value="n">否</option>
                    </select>
                </div>
            </div>
            <div class="control-group span10">
                <div class="controls">
                    <label class="control-label">录入日期:</label>
                    <input name="startDate" class="input-small calendar" type="text" id="startDate"/>
                    <label>&nbsp;-&nbsp;</label>
                    <input name="endDate" class="input-small calendar" type="text" id="endDate"/>
                </div>
            </div>

        </li>
        <li>
            <div class="form-actions span12">
                <button type="submit" class="button  button-primary">
                    查询
                </button>
                <#if checkPrivilege("/manage/product/insert") >
                    <a href="${basepath}/manage/product/toAdd" class="button button-success">添加</a>
                </#if>
                <a  class="button button-danger"  href="javascript:delFunction()">
                    删除
                </a>
                <a type="submit" class="button  button-warning">
                    上架
                </a>
                <a type="submit" class="button  button-warning">
                    下架
                </a>
            </div>
        </li>
    </ul>
</form>
<div id="grid"></div>
<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '商品编号', dataIndex: 'id', width: 80},
                {title: '名称', dataIndex: 'name', width: 80},
                {title: '录入日期', dataIndex: 'status', width: 80},
                {
                    title: '新品', dataIndex: 'isnew', width: 80, renderer: function (data) {
                    if (data == "y") {
                        return '<img src="${basepath}/resource/images/action_check.gif">';
                    }
                }
                },
                {
                    title: '特价', dataIndex: 'sale', width: 80, renderer: function (data) {
                    if (data == "y") {
                        return '<img src="${basepath}/resource/images/action_check.gif">';
                    }
                }
                },
                {title: '浏览次数', dataIndex: 'hit', width: 80},
                {title: '销量', dataIndex: 'sellcount', width: 80},
                {
                    title: '状态', dataIndex: 'status', width: 80, renderer: function (data) {
                    if (data == "1") {
                        return '<img src="${basepath}/resource/images/action_add.gif">';
                    }
                    else if (data == "2") {
                        return '<img src="${basepath}/resource/images/action_check.gif">';
                    }
                    else if (data == "3") {
                        return '<img src="${basepath}/resource/images/action_delete.gif">';
                    }
                }
                },
                {
                    title: '操作', dataIndex: 'id', width: 80, renderer: function (value) {

                    <#if checkPrivilege("/manage/product/edit")>
                        return '<a href="${basepath}/manage/product/toEdit?id=' + value + '">编辑</a>';
                    <#else>
                        return "";
                    </#if>


                }
                }
            ];
    var store = new Store({
                url: 'loadData',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    status: $("#status").val()
                },
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格

                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });

    /**
     * 删除选中记录
     */
    function delFunction(){
        var selections = grid.getSelection();
        var ids=new Array();
        for(var i=0;i<selections.length;i++){
            ids[i]=selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/manage/product/deletesJson",
            dataType: "json",
            data: {
                idArr:ids
            },
            success: function (data) {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });

    }
</script>
</@page.pageBase>